import 'package:awesome_project/gen/colors.gen.dart';

import 'package:awesome_project/route/app_router.dart';
import 'package:awesome_project/utils/sp_utils.dart';

import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:mpflutter_core/mpflutter_core.dart';
import 'package:mpflutter_wechat_api/mpflutter_wechat_api.dart' hide Size;

void main() async {
  await initRouter();
  WidgetsFlutterBinding.ensureInitialized();
  await SpUtil.getInstance();
  runMPApp(const ProviderScope(child: MyApp()));
  // runApp(const ProviderScope(child: MyApp()));
  /**
   * 务必保留这段代码，否则第一次调用 wx 接口会提示异常。
   */
  if (kIsMPFlutter) {
    try {
      wx.$$context$$;
    } catch (e) {}
  }
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp.router(
      title: '涉税专业服务机构',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        useMaterial3: true,
        elevatedButtonTheme: ElevatedButtonThemeData(
          style: ElevatedButton.styleFrom(
              minimumSize: const Size(40, 30),
              padding: const EdgeInsets.symmetric(horizontal: 10),
              backgroundColor: Colors.blue,
              foregroundColor: Colors.white,
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(5))),
        ),
        scaffoldBackgroundColor: ColorName.bgGray,
        dividerTheme: const DividerThemeData(color: ColorName.bgGray),
        textButtonTheme: TextButtonThemeData(
          style: TextButton.styleFrom(
            foregroundColor: Colors.blue,
          ),
        ),
        appBarTheme: const AppBarTheme(
          foregroundColor: Colors.black,
          surfaceTintColor: Colors.white,
          backgroundColor: Colors.white,
          elevation: 0,
          titleTextStyle: TextStyle(fontSize: 16, color: Colors.black),
          centerTitle: true,
        ),
        splashFactory: NoSplash.splashFactory,
        fontFamily: "MiniTex",
        fontFamilyFallback: ["MiniTex"],
        /**
         * 使用 iOS 风格页面转场
         */
        platform: TargetPlatform.iOS,
      ),
      routerConfig: appRouter,
      builder: FlutterSmartDialog.init(),
    );
  }
}
